import { AlertDialog } from "./ui/alert_dialog"
import { delay } from "./utils";


export const runAction = async<T> (title: string, msg: string, f: (_: AlertDialog) => Promise<T>) => {
    const dialog = new AlertDialog(title, msg);
    try {
        dialog.prog(msg);
        await f(dialog);
        dialog.success('成功');
        await delay(800);
        dialog.close();
    } catch (msg) {
        dialog.error(msg as string);
    }
}


export const runAsync = async<T> (f: () => Promise<T>) => {
    try {
        await f();
    } catch (msg) {
        new AlertDialog('错误', '').error(msg as string);
    }
}
